package com.itgaoshu.hospitalproject.mapper;

import com.itgaoshu.hospitalproject.bean.Baoque;
import com.itgaoshu.hospitalproject.bean.Drugstore;
import com.itgaoshu.hospitalproject.bean.Ypharmacy;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OutinstoreMapper {
    //查询报缺单
    @Select("select * from baoque order by baoqueid desc")
    List<Baoque> selbaoquedan();
    //根据补给单的名字查询对应的仓库药品
    @Select("select rugstoreId,drugstorenum,drugstoreName,batch from drugstore where drugstoreName=#{drugstoreName}")
    List<Drugstore> selbaoquedrugname(Drugstore drugstore);
    //减去库存数量
    @Update("update Drugstore set drugstorenum=(drugstorenum-#{drugstorenum}) where rugstoreId=#{rugstoreId}")
    int deleteDrugsByshuliang(Drugstore drugstore);
    //查询药品表是否已存在药出库的药
    @Select("SELECT count(*)from pharmacy where pharmacyName=#{pharmacyName}")
    int selpharymacyname(Ypharmacy ypharmacy);
    //出库的
    @Update("update pharmacy set drugstorenum=(drugstorenum+#{drugstorenum}) where pharmacyName=#{pharmacyName}")
    int uppharymacy(Ypharmacy ypharmacy);
    //补给的
    @Update("update pharmacy set drugstorenum=(drugstorenum+#{drugstorenum}) where pharmacyName=#{drugstoreName}")
    int uppharmacynumber(Drugstore drugstore);
    //在仓库里直接删掉该药品
    @Update("delete from Drugstore where rugstoreId=#{rugstoreId}")
    int deleteDrugsByName(Drugstore drugstore);
    //查看该药品库存数
    @Select(" select drugstorenum from drugstore where rugstoreId=#{rugstoreId}")
    int seldrugnamenum(Drugstore drugstore);
    @Select("select baoqueNum from baoque where baoqueName=#{pharmacyName}")
    int selbaoquenamenum(Ypharmacy ypharmacy);
    @Update("delete from baoque where baoqueName=#{baoqueName}")
    int delbaoquenamenum();
    @Select("select count(*) from baoque")
    int selbaoquecount();
    @Select("select count(* )from baoque where baoqueName=#{pharmacyName}")
    int selbaoqueName(Ypharmacy ypharmacy);
    @Update("update baoque set baoqueNum=(baoqueNum-#{drugstorenum}) where baoqueName=#{pharmacyName}")
    int upbaoquenumber1(Ypharmacy ypharmacy);
    @Update("insert into pharmacy(warehouseId,pharmacyName,drugstorenum,\n" +
            "        skullId,unit,sellingPrice,area,produceDate,validDate,skullbatch,type)\n" +
            "        values(#{warehouseId},#{pharmacyName},#{drugstorenum},\n" +
            "        #{skullId},#{unit},#{sellingPrice},#{area},#{produceDate},\n" +
            "        #{validDate},#{skullbatch},#{type})")
    int addTopharmacy(Ypharmacy ypharmacy);

}
